﻿using SharpDX;
using System;

namespace MikadoShooter
{
    public static class RandomExt
    {
        private static readonly Random random;

        static RandomExt()
        {
            random = new Random();
        }

        public static Vector4[] GetRandomPos()
        {
            return new[] 
            {
                new Vector4(GetRandom(), Math.Abs(GetRandom()), 0.0f, 1.0f),
                new Vector4(GetRandom(), Math.Abs(GetRandom()), 0.0f, 1.0f)
            };
        }

        public static Vector4 GetRandomColor(int colors)
        {
            if (3 > colors || colors > 6)
                throw new ApplicationException("GetRandomColor error");

            switch (random.Next(0, colors))
            {
                case 0:
                    return StdColors.RedColor;
                case 1:
                    return StdColors.GreenColor;
                case 2:
                    return StdColors.BlueColor;
                case 3:
                    return StdColors.CyanColor;
                case 4:
                    return StdColors.MagentaColor;
                case 5:
                    return StdColors.YellowColor;
            }

            throw new ApplicationException("GetColor error");
        }

        private static float GetRandom()
        {
            double val = random.NextDouble();           // range 0.0 to 1.0
            val -= 0.5;                                 // expected range now -0.5 to +0.5
            val *= 2;                                   // expected range now -1.0 to +1.0

            return (float)val;
        }
    }
}
